<?php
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

$sView = $_REQUEST['sView'];

?>

<input type="hidden" id="window_view" value="<?php print $sView; ?>" />

<script language="javascript" type="text/javascript">
	$(document).ready(function() {
		var window_selector = "#window_holder";
		var form_selector = "form[name='form_job_add']";
		var view = "job-add";

		var $form = $(form_selector);
		var $window_holder = $(window_selector);

		$form.submit(function() {
			var post_data = {};
			var inputs = $(":input", form_selector);
			inputs.each(function() {
				if (this.name.length > 0 && this.name != "sView") {
					post_data[this.name] = this.value;
				}
			});

			var result = $.ajax({
				type: "POST",
				url: "index.php?window&sView=" + view,
				data: post_data,
				success: function(response_text, text_status, request) {
					var redirect = result.getResponseHeader("MiJob-Window-Location");
					if (redirect != null) {
						location.href = redirect;
					}
					else {
						$window_holder.html(response_text);
						var inputs = $window_holder.find(":input[type != 'hidden']");
						if (inputs.length) {
							inputs[0].focus();
						}
						else {
							inputs.focus();
						}
					}
				}
			});

			return false;
		});
	});
</script>

<?php

loadBox($sView);

?>
